package com.cysion.study.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.cysion.study.R
import com.cysion.study.entity.ApprovalEntity
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.study.ktbox.base.ITEM_CLICK
import kotlinx.android.synthetic.main.item_pendings.view.*

class PendingsAdapter(mEntities: MutableList<ApprovalEntity>, mContext: Context) :
    BaseAdapter<ApprovalEntity>(mEntities, mContext) {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): BaseViewHolder<ApprovalEntity> {

        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_pendings, parent, false)
        )
    }

    class ProMoneyHolder(itemView: View) : BaseViewHolder<ApprovalEntity>(itemView) {
        override fun fillData(obj: ApprovalEntity, position: Int) {
            itemView?.apply {
                //type":0, //审批类型: 0.请假 1.报销 2.调休
                if (obj.type == "0") {
                    itemView.tv_title.text = "请假"
                } else if (obj.type == "1") {
                    itemView.tv_title.text = "报销"
                } else if (obj.type == "2") {
                    itemView.tv_title.text = "调休"
                }
                itemView.tv_time.text = obj.stName
                itemView.tv_name.text = obj.createTime
                Glide.with(context).load(obj.imageUrls)
                    .apply(RequestOptions.placeholderOf(R.mipmap.place_holder))
                    .into(itemView.iv_head)

                //status":0, //审批状态:0.审核中 1.审核通过 2.审核不通过  3.撤销
                if (obj.status == "0") {
                    itemView.tv_status.text = "审核中"
                } else if (obj.status == "1") {
                    itemView.tv_status.text = "审核通过"
                } else if (obj.status == "2") {
                    itemView.tv_status.text = "审核不通过"
                } else if (obj.status == "3") {
                    itemView.tv_status.text = "撤销"
                }
                itemView.setOnClickListener {
                    mOnTypeClickListener?.invoke(obj, position, ITEM_CLICK)
                }

            }

        }

    }

}



